<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div class="box">1</div>
    <div class="bigbox">2</div>
    <div>3</div>
    <div>4</div>
  </body>
  <script>
    //写个入口函数
    window.onload = function () {
      //获取单个元素
      const box = document.querySelector(".box");
      console.log(box); //<div class="box">1</div>

      //获取全部元素
      const boxAll = document.querySelectorAll("div");
      //key是指元素，index是下标
      boxAll.forEach(function (key, index) {
        console.log(key, index);
      });
    };
  </script>
</html>
